package com.louis.domain.i18n;

import javax.persistence.*;

import com.louis.domain.DomainObject;

import java.text.MessageFormat;
import java.util.*;

/**
 * 
 * <p>
 * Message
 * </p>
 * 
 * @author: louisjiang
 * @version: 1.0.0,Apr 23, 20124:45:16 PM
 */
@Entity
@Table(name = "message")
public class Message extends DomainObject {

	private static final long	serialVersionUID	= 7573156282429772130L;

	private String				code;

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "message")
	private List<Translation>	translations		= new ArrayList<Translation>();

	public Message() {
	}

	public Message(String code, List<Translation> translations) {
		this.code = code;
		this.translations = translations;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public List<Translation> getTranslations() {
		return translations;
	}

	public void setTranslations(List<Translation> translations) {
		this.translations = translations;
	}

	public Map<Locale, MessageFormat> getMessageFormats() {
		Map<Locale, MessageFormat> localeMessageFormatMap = new HashMap<Locale, MessageFormat>();
		for (Translation translation: translations) {
			localeMessageFormatMap.put(translation.getLocale(), translation.getMessageFormat());
		}
		return localeMessageFormatMap;
	}
}